from wormbane.engine.generate_level import generate_level
from wormbane.engine.save_game import load_game
from wormbane.model.game import Game
from wormbane.model.weapon import Weapon
from wormbane.model.races.drow import Drow

def load_or_create_game():
    try:
        game = load_game()
        game.write(game.hero, 'returns to Wormbane')
    except IOError:
        game = create_game()
        game.write('Welcome to Wormbane.')
    return game

def create_game():
    game = Game()
    game.level = generate_level(1)
    game.hero = Drow.create_equipped_monster()
    for thing in game.hero.inv:
        if thing.is_item:
            thing.beatitude_id = True
            thing.enchantment_id = True
            if thing.cursed:
                thing.beatitude = 'uncursed'
            if thing.enchantment < 0:
                thing.enchantment = 0
    game.hero.name = 'Elemel'
    game.hero.health = 100
    game.hero.move_to(game.level.cells[game.level.stair_up_pos])
    return game
